<?php
namespace App\Services\Collection;
use App\Services\CommonService;
use App\Model\Company;
use Illuminate\Support\Facades\DB;

/*
 *  我的收藏
 */
class CollectionService extends CommonService{

    /*
     *  我的收藏  公司
     *  @ $id  用户id
     */
    static function company($id){
        $res = DB::select("select com.name,com.tag,com.id from collection as c inner join company as com on c.correlation_id=com.id where c.user_id=$id and c.type=5");
        // 将对象转化为 数组
        foreach ( $res as &$v ){
            $v = (array)$v;
        }
        return $res;
    }

    /*
     *  公司详情
     *  @ $id  公司id
     */
    static function companys($id){
        $flights = Company::where('id', $id)
            ->take(1)
            ->get();
        // 将对象转化为数组
        foreach ( $flights as &$v ){
            $v = (array)$v;
        }
        return $flights;
    }

    /*
     *  我收藏的职位
     *  @ $id  用户id
     */
    static function position($id){
        $res = DB::select("select p.position_name,company.name,p.address,p.nature_work,p.education,p.low,p.high,p.job_category from collection as c inner join position as p on c.correlation_id=p.position_id  join company on p.company_id=company.id where c.user_id=$id and c.type=3");
        // 将对应的状态改为 名称
        foreach( $res as &$v ){
            $v = (array)$v;
            switch ($v['nature_work']){
                case 1:$v['nature_work'] = "实习";break;
                case 2:$v['nature_work'] = "正式";;break;
                case 3:$v['nature_work'] = "日结";;break;
                case 4:$v['nature_work'] = "月结";;break;
                case 5:$v['nature_work'] = "年薪";;break;
            }
            switch ($v['education']){
                case 1:$v['education'] = "初中";break;
                case 2:$v['education'] = "高中";;break;
                case 3:$v['education'] = "大学";;break;
                case 4:$v['education'] = "本科";;break;
            }
            switch ($v['job_category']){
                case 1:$v['job_category'] = "双休";break;
                case 2:$v['job_category'] = "单休";;break;
                case 3:$v['job_category'] = "月休";;break;
            }
//            if( $v['nature_work'] == 1 ){
//                $v['nature_work'] = "实习";
//            }elseif ( $v['nature_work'] == 2 ){
//                $v['nature_work'] = "正式";
//            }elseif ( $v['nature_work'] == 3 ){
//                $v['nature_work'] = "日结";
//            }elseif ( $v['nature_work'] == 4 ){
//                $v['nature_work'] = "月结";
//            }elseif ( $v['nature_work'] == 5 ){
//                $v['nature_work'] = "年薪";
//            }
//            if( $v['education'] == 1 ){
//                $v['education'] = "初中";
//            }elseif ( $v['education'] == 2 ){
//                $v['education'] = "高中";
//            }elseif ( $v['education'] == 3 ){
//                $v['education'] = "大学";
//            }elseif ( $v['education'] == 4 ){
//                $v['education'] = "本科";
//            }
//            if( $v['job_category'] == 1 ){
//                $v['job_category'] = "双休";
//            }elseif ( $v['job_category'] == 2 ){
//                $v['job_category'] = "单休";
//            }elseif ( $v['job_category'] == 3 ){
//                $v['job_category'] = "月休";
//            }
        }
        return $res;
    }

    /*
     *  我收藏的咨询
     *  @ $id  用户id
     */
    static function information($id){
        $res = DB::select("select i.id,i.name,i.img,i.content,i.created_at from collection as c inner join information as i on c.correlation_id=i.id where c.user_id=$id and c.type=1");
        // 将对象转化为数组
        foreach ( $res as &$v ){
            $v = (array)$v;
        }
        return $res;
    }


}